package com.weipt.oper;

import java.lang.management.MemoryUsage;

/**
 * @program: Learning
 * @description:
 * @Company: 汇华(北京)信息咨询服务有限公司
 * @author: peter.wei
 * @create: 2020-07-25 10:55
 **/
public class join {

    static class MyRunnable implements Runnable{

        @Override
        public void run() {
            for (int i = 0; i < 200; i++) {
                System.out.println(Thread.currentThread().getName()+"-->在跑"+i);
            }
        }
    }

    public static void main(String[] args) {

        MyRunnable myRunnable = new MyRunnable();
        Thread t1 = new Thread(myRunnable, "t1");
        Thread t2 = new Thread(myRunnable, "t2");
        Thread t3 = new Thread(myRunnable, "t3");
        t1.start();
        t2.start();
        try {
            t2.join();  //当t1已经拿到资源后，t2的join不会影响到t1，指挥影响到主线程和后面的线程
            //t2不结束，t3和main都在排队
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t3.start();

        for (int i = 0; i < 500; i++) {
            System.out.println(Thread.currentThread().getName()+"-->凑热闹在跑"+i);
        }
    }
}